package milkproduction.controller;

import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import milkproduction.dao.GenerateDAO;
import milkproduction.to.ContainerTO;
import milkproduction.to.OrderTO;
import milkproduction.to.RowMilkTO;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

public class GenerateController implements ServletContextListener {
	//GenerateDAO gDao = GenerateDAO.getInstace();
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("끝");
		
	}
@Override
	public void contextInitialized(ServletContextEvent event) {
	
	GenerateDAO gDao = GenerateDAO.getInstace();
	
	System.out.println("시작ㄹㅇㄴㄹㄴㅇㄹㄴㅇㄹㄴㅇㄹㄴㅇ");

//order 생성
OrderTO oto = new OrderTO();
 	//public void milkOrder(){
 	oto.setQuantity((int)(Math.random()*3001)+17000); //원유량 
 	ArrayList ordererList = gDao.selectByorderer();
 	oto.setOrderer((String) ordererList.get((int)(Math.random()*7))); //주문자
 	oto.setOrderNo(gDao.selectOrderSEQ());//시퀀스;
	gDao.insertOrder(oto);
System.out.println("주문: "+oto);
 	//}

	//원유 생산
//public void milkProduction(){
		RowMilkTO rmto= new RowMilkTO();
	rmto.setRowMilkNO(gDao.selectRowMilkSEQ());//원유 시퀀스	
	rmto.setCapacity(oto.getQuantity()+oto.getQuantity()/10);	//원유량 
		ArrayList mlist = gDao.selectByMilk();
		int num = (int)(Math.random()*5);
	rmto.setSupplier((String)mlist.get(num));//생성목장
	gDao.insertRowMilk(rmto);
System.out.println("원유 생산 :" + rmto);
//	}
	//병 생산
//	public void bottleProduction(){
		ContainerTO cto = new ContainerTO();
		cto.setContainerNo(gDao.selectBottleSEQ());//병 시퀀스
		cto.setQuantity((int)oto.getQuantity()+oto.getQuantity()/10);//원유량 = 병의 수량
		ArrayList blist = gDao.selectBottle();
		int num2 = (int) (Math.random()*5);
		cto.setSupplier((String)blist.get(num2));//병메이커
		gDao.insertBottle(cto);
System.out.println("병 샌산 :" + cto);
	//}
}



}//EOF
